
var subsets = function(nums: number[]): number[][] {
    var loop = (tail: number[]): number[][] => {
        let result: number[][] = []
        let head = tail.shift()
        result.push([head])
        if (tail.length > 0) {
            let tails = loop(tail.slice());
            for(var t of tails) {
                result.push(t)
                result.push(t.slice().concat(head))
            }
        }
        return result;
    }
    var answer = loop(nums.slice()).concat([[]])
    return answer;
};

var input78: number[]
var answer78: number[][]

// answer78 = [
//   [3],
//   [1],
//   [2],
//   [1,2,3],
//   [1,3],
//   [2,3],
//   [1,2],
//   []
// ]    

// function 2dToString(xs: number[][]) {
//     return xs.map(ys => ys.join(',')).join(';')
// }

answer78 = subsets([1,2,3])

console.log('The End')